<template>
  <section class="component account-adjustment-apply">
    <el-form :model="model" :rules="rules" label-width="100px" ref="model">
      <el-form-item label="案件调整类型" prop="typeId">
        <el-select clearable placeholder="请选择" v-model="model.typeId">
          <el-option
            :key="id"
            :label="name"
            :value="id"
            v-for="{ id, name } in tagList"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="调整原因" prop="note">
        <el-input
          v-model.trim="model.note"
          type="textarea"
          :maxlength="200"
          show-word-limit
        ></el-input>
      </el-form-item>
    </el-form>

    <div class="confirm-button">
      <el-button @click="emitClose">取消</el-button>
      <el-button @click="onClickCommit">提交</el-button>
    </div>
  </section>
</template>

<script lang="ts">
import { Vue, Component, Emit, Prop } from "vue-property-decorator";
import { CustomerGroupManageService } from "~/services//domain-service/customer-group-manage.service";
import { Dependencies, Layout } from "~/core/decorator";
const CollectionExecutionModule = namespace("collection-execution");
import { namespace } from "vuex-class";

@Component({
  components: {}
})
export default class AccountAdjustmentApply extends Vue {
  @Dependencies(CustomerGroupManageService)
  private customerGroupManageService: CustomerGroupManageService;
  @Prop() private topInfo;
  @CollectionExecutionModule.State private caseNo;
  @CollectionExecutionModule.State private personalName;
  @CollectionExecutionModule.State private personalNo;

  private model: any = {
    typeId: "",
    note: ""
  };
  private tagList: any = [];
  private rules: any = {
    typeId: { required: true, message: "请选择案件调整类型" },
    note: { required: true, message: "请输入调整原因" }
  };

  @Emit("close") private emitClose() {}

  /**
   * 提交
   */
  private onClickCommit() {
    const form: any = this.$refs.model;
    if (!form) return;
    form.validate(valid => {
      if (!valid) return;
      const obj = this.tagList.find(v => v.id === this.model.typeId);
      const params = {
        ...this.model,
        caseNumber: this.caseNo,
        personalName: this.personalName,
        personalId: this.personalNo
      };
      params.typeName = obj ? obj.name : "";
      this.customerGroupManageService
        .singleAdjustment(params)
        .subscribe(data => {
          this.$message.success("操作成功！");
          this.emitClose();
        });
    });
  }

  private getCaseTagList() {
    const form: any = this.$refs.model;
    form.resetFields();
    this.customerGroupManageService.getEffectTypes().subscribe(data => {
      this.tagList = data;
    });
  }
}
</script>
